package zero.tech.games.gate.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import zero.tech.games.entity.games.ClubMemberProxy;

public interface ClubMemberProxyMapper {

	@Insert("insert into club_member_proxy(club_id,uid,father_uid,fanyong) values(#{club_id},#{uid},#{father_uid},#{fanyong})")
	void insert(ClubMemberProxy clubMemberProxy);

	@Select("select * from club_member_proxy where club_id=#{club_id} and uid=#{uid}")
	ClubMemberProxy getClubMemberProxy(@Param("club_id")int club_id,@Param("uid") int uid);

	@Select("select t1.uid from club_member_proxy t1 left join club_member_role t2 on t1.club_id=t2.club_id and t1.uid=t2.uid "
			+ " where t1.club_id=#{club_id} and t1.father_uid=#{uid} and t2.role=0 limit #{start},#{pageLength}")
	List<Integer> loadZsUidsByPage(@Param("club_id")int club_id,@Param("uid") int uid, @Param("start")int start, @Param("pageLength")int pageLength);
	
	@Select("select count(1) from club_member_proxy t1 left join club_member_role t2 on t1.club_id=t2.club_id and t1.uid=t2.uid "
			+ "where t1.club_id=#{club_id} and t1.father_uid=#{uid} and t2.role=0")
	int loadZsUidsTotalCountByPage(@Param("club_id")int club_id, @Param("uid")int uid);

	@Select("select count(1) from club_member_proxy t1 left join club_member_role t2 on t1.club_id=t2.club_id and t1.uid=t2.uid "
			+ "where t1.club_id=#{club_id} and t1.father_uid=#{uid} and t2.role=1")
	int loadZsHehuorenTotalCountByPage(@Param("club_id")int club_id, @Param("uid")int uid);
	
	@Select("select t1.uid from club_member_proxy t1 left join club_member_role t2 on t1.club_id=t2.club_id and t1.uid=t2.uid "
			+ " where t1.club_id=#{club_id} and t1.father_uid=#{uid} and t2.role=1 limit #{start},#{pageLength}")
	List<Integer> loadZsHehuorenByPage(@Param("club_id")int club_id,@Param("uid") int uid, @Param("start")int start, @Param("pageLength")int pageLength);

	@Update("update club_member_proxy set fanyong=#{fanyong} where club_id=#{club_id} and uid=#{uid}")
	void updateFanyong(@Param("club_id")int club_id,@Param("uid") int uid, @Param("fanyong")float fanyong);

	@Update("update club_member_proxy set father_uid=#{father_uid} where club_id=#{club_id} and father_uid=#{uid}")
	void rebind(@Param("club_id")int club_id,@Param("father_uid")int father_uid,@Param("uid") int uid);

	@Delete("delete from club_member_proxy where club_id=#{club_id} and uid=#{uid}")
	void delete(@Param("club_id")int club_id, @Param("uid")int uid);

	@Select("select fanyong from club_member_proxy where club_id=#{club_id} and father_uid=#{uid} order by fanyong desc limit 1")
	Float getSubMaxFanyong(int club_id, int uid);

}
